// import Router from 'vue-router';
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { getToken } from "@/utils/cache";
import { CacheToken } from '@/constants/cacheKey';
 
// Vue.use(Router);
const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        redirect: '/dashboard',
    },
    {
        path: '/usehelp',
        component: ()=> import('../components/usehelp/UseHelp.vue'),
        meta: { title: '系统使用帮助' },
    },
    {
        path: '/help',
        component: ()=> import('../components/usehelp/help.vue'),
        meta: { title: '展视互动使用手册' },
    },
    /******************************************crm ******************************************************/
    // crm 显示vue页面   结束 
    {
        path: '/home',
        component: ()=> import('../layout/index.vue'),
        meta: { title: '自述文件' },
        children:[
            {
                path: '/dashboard',
                component: ()=> import('../components/page/Dashboard.vue'),
                meta: { 
                    title: '系统首页' ,
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            /** -----------------------------------示例页面----------------------------------------- */

            /** --------------------------------------示例页面-----------------------------------------*/

            /******************************************education******************************************************/
            {
                path: '/work/user',
                name: 'user',
                component: ()=> import('@/views/work/bmAndStaff/user.vue'),
                meta: { 
                    title: '部门 & 员工',
                    isUseCache: false,  // 这个字段的意思稍后再说      
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/work/app',
                name: 'app',
                component: () => import('@/views/work/applyManage/app.vue'),
                meta: { 
                    title: '应用管理',
                    isUseCache: false,  // 这个字段的意思稍后再说      
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/addApplyManage',
                name: 'addApplyManage',
                component: () => import('@/views/work/applyManage/addApplyManage.vue'),
                meta: { 
                    title: '新增应用',
                    isUseCache: false,  // 这个字段的意思稍后再说      
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/work/log',
                name: 'log',
                component: () => import('@/views/work/sysLog/log.vue'),
                meta: { 
                    title: '系统日志',
                    isUseCache: false,  // 这个字段的意思稍后再说      
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/work/mailGroup',
                name: 'mailGroup',
                component: () => import('@/views/work/mailGroup/mailGroup.vue'),
                meta: { 
                    title: '263邮箱组',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/sys/dept',
                name: 'dept',
                component: ()=> import('@/views/sys/orgSchema/dept.vue'),
                meta: { 
                    title: '部门设置',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/sys/func',
                name: 'func',
                component: ()=> import("@/views/sys/func.vue"),
                meta: { 
                    title: '资源设置',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },      
            {
                path: '/sys/role',
                name: 'role',
                component: () => import('@/views/sys/orgSchema/role.vue'),
                meta: { 
                    title: '角色设置',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/sys/position',
                name: 'position',
                component: () => import('@/views/sys/orgSchema/position.vue'),
                meta: { 
                    title: '职位&权限',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },       
            /******************************************jiaoWu******************************************************/
            {
                path: '/showqrzclassmanage',
                name:'showqrzclassmanage',
                component: ()=> import('@/components/page/jiaowu/qrzclassmanage/showqrzclassmanage.vue'),
                meta: { 
                    title: '班级管理',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/addqrzclass',
                name:'addqrzclass',
                component: ()=> import('@/components/page/jiaowu/qrzclassmanage/addqrzclass.vue'),
                meta: { 
                    title: "新增班级",
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/editqrzclass',
                name:'editqrzclass',
                component: ()=> import('@/components/page/jiaowu/qrzclassmanage/edit_class.vue'),
                meta: { 
                    title: "编辑班级",
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            },
            {
                path: '/schoolcoursecycle',
                name: 'schoolcoursecycle',
                component: ()=> import('@/components/page/jiaowu/schoolcoursecycle/schoolCourseCycle.vue'),
                meta: { 
                    title: '上课周期设置',
                    isUseCache: false,    
                    keepAlive: true  // 通过此字段判断是否需要缓存当前组件
                }
            }, 
            /*****************************************成绩分析  resultAnalysis********************************/
            {
                path: '/classResultAnalysis',
                name: 'classResultAnalysis',
                component: ()=> import('@/components/page/resultAnalysis/classResultAnalysis/main/class_result_analysis.vue'),
                meta: {
                    title: '班级成绩分析',
                    isUseCache: false,
                    keepAlive: true
                }
            },   
            {
                path: '/stuComDetails',
                name: 'stuComDetails',
                component: ()=> import('@/components/page/resultAnalysis/classResultAnalysis/main/compare_last_4/stu_com_details.vue'),
                meta: {
                    title: '学生对比详情',
                    isUseCache: false,
                    keepAlive: true
                }
            },
            {
                path: '/stepStuDetails',
                name: 'stepStuDetails',
                component: ()=> import('@/components/page/resultAnalysis/classResultAnalysis/main/compare_last_4/step_stu_details.vue'),
                meta: {
                    title: '学生详情',
                    isUseCache: false,
                    keepAlive: true
                }
            },           
            /*****************************************成绩分析  resultAnalysis 结束********************************/
        ]
    },
    {
        path: "/error",
        name: "error",
        component: ()=> import ('@/views/error/error.vue'),
        meta: { title: "404", keepAlive: false }
    }
];
const router = createRouter({
    history: createWebHashHistory(),
    routes//路由 对象
})
//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    let hours = 12;//3个小时
    let expires = new Date(new Date() * 1 + (1000 * 60 * 60 * hours));//1000 1s
   /*  window.addEventListener('message', function(event) {
        var data = event.data;
        if(event && (typeof data !== 'object')){
            window.name = data;
        }
    }); */
    if(window.name){   
        // setCache(CacheToken, window.name);   
        Cookies.set('work_token', window.name, { expires: expires });//12 小时后失效
    }
    /* 路由发生变化修改页面title */
  /*   if (to.meta.title === '系统使用帮助' || to.meta.title === '展视互动使用手册') {
        document.title = to.meta.title
    }
    if (to.name === 'report' ) {
        to.meta.title =to.params.name;
    }
    next() */
    next();
    //token
    const token = getToken();
    if (to.path !== "/login") {
        
    }
})
export const errorRoute: Array<RouteRecordRaw> = [
    {
        path: "/:path(.*)*",
        redirect: { path: "/error", query: { to: 404 }, replace: true },
        meta: { isNavigationMenu: false }
    }
];
export default router